package com.gxuwz.medical.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gxuwz.medical.domain.medical.Medical;

public class MedicalServlet extends BaseServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doPost(req, resp);
	}

	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String m = req.getParameter("m");
		if ("list".equals(m)) {
			process(req, resp, "/page/medical/medical_list.jsp");
		} else if ("input".equals(m)) {
			process(req, resp, "/page/medical/medical_add.jsp");
		} else if ("add".equals(m)) {
			add(req, resp);
		}else if("del".equals(m)){
			del(req,resp);
			process(req,resp,"/page/medical/medical_list.jsp");
		}else if("edit".equals(m)){
			edit(req,resp);
		}else if("get".equals(m)){
			process(req,resp,"/page/medical/medical_edit.jsp");
		}
	}
	
	protected void add(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String medicalcode = req.getParameter("medicalcode");
		String organizecode= req.getParameter("organizecode");
		String medicalname = req.getParameter("medicalname");
		String diqucode    = req.getParameter("diqucode");
		String areacode    = req.getParameter("areacode");
		String grade       = req.getParameter("grade");
		String type        = req.getParameter("type");
		//1:实例化Medical
		Medical medical =new Medical();
		//2:调用方法
		try{
			medical.addMedical(medicalcode, organizecode, medicalname,diqucode,areacode,grade,type);
			process(req, resp, "/page/medical/medical_list.jsp");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	

	protected void del(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String medicalcode = req.getParameter("id");
		Medical medical = new Medical();
		try{
		medical.delMedical(medicalcode);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	
	protected void edit(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String medicalcode = req.getParameter("medicalcode");
		String organizecode= req.getParameter("organizecode");
		String medicalname = req.getParameter("medicalname");
		String diqucode    = req.getParameter("diqucode");
		String areacode    = req.getParameter("areacode");
		String grade       = req.getParameter("grade");
		String type        = req.getParameter("type");
		//1:实例化Medical
		Medical medical =new Medical();
		//2:调用方法
		try{
			medical.editChronic(medicalcode, organizecode, medicalname,diqucode,areacode,grade,type);
			process(req,resp,"/page/medical/medical_list.jsp");
		}catch(Exception e){
			e.printStackTrace();
		}
	}

}
